import request from "@/utils/request";
import {IRoutersMenuItem} from "@/stores/reducers/userInfoReducers";
import {createIcon} from "@/utils/iconUtil";
import {LayoutEnum} from "@/enums/LayoutEnum";

export async function getRouters(): Promise<any> {
    return request('/system/menu/getRouters');
}

export function convertCompatRouters(childrens: IRoutersMenuItem[]): any[] {
    return childrens.map((item: IRoutersMenuItem) => {
        return {
            path: item.path,
            name: item.name,
            hidden: item.hidden,
            icon: createIcon(item.meta.icon),
            //  icon: item.meta.icon,
            title: item.meta.title,
            routes: item.children ? convertCompatRouters(item.children) : undefined,
            hideChildrenInMenu: item.hidden,
            hideInMenu: item.hidden,
            component: item.component,
            authority: item.perms,
            needAuth: true,
            pageType: item.children ? item.component : LayoutEnum.LAYOUT
        };
    });
}